import express, { Request, Response, NextFunction } from "express";
import { query, validationResult } from "express-validator";

const router = express.Router();

router.get(
  "/",
  [query("name").notEmpty().withMessage("name参数不为空")],
  (req: Request, res: Response, next: NextFunction) => {
    try {
      const errors = validationResult(req);
      if (!errors.isEmpty()) {
        throw new Error(errors.array()[0].msg);
      }

      res.json({ code: 200, msg: "请求成功" });
    } catch (e) {
      res.json({ code: 500, msg: (e as Error).message });
    }
  }
);

export default router;
